// router/index.js
import { createRouter, createWebHashHistory } from 'vue-router';

// Imports from original index.js
import MainHome from '../views/MainHome.vue';
import PrivateChat from '../components/PrivateChat.vue';
import MessageHome from '../views/MessageHome.vue';
import SearchResult from '../views/SearchResult.vue';
import PersonalHome from '../user_profile/PersonalHome.vue';

// Imports for Login and Register
import UserLogin from '../views/UserLogin.vue';
import UserRegister from '../views/UserRegister.vue';
import ForgotPassword from '../views/ForgotPassword.vue';
import ResetPassword from '../views/ResetPassword.vue';
const AdminLayout = () => import('../admin/layouts/AdminLayout.vue');
const AdminDashboard = () => import('../admin/views/Dashboard.vue');
const AdminUsers = () => import('../admin/views/Users.vue');
const AdminRoles = () => import('../admin/views/Roles.vue');
const AdminMenus = () => import('../admin/views/Menus.vue');


const routes = [
  // Login and Register routes
  { 
    path: '/', 
    redirect: '/login' 
  },
  { 
    path: '/login', 
    component: UserLogin 
  },
  { 
    path: '/register', 
    component: UserRegister
  },
  {
    path: '/forgot-password',
    component: ForgotPassword
  },
  {
    path: '/reset-password',
    component: ResetPassword
  },

  // Admin routes
  {
    path: '/admin',
    component: AdminLayout,
    children: [
      { path: '', redirect: '/admin/dashboard' },
      { path: 'dashboard', component: AdminDashboard },
      { path: 'users', component: AdminUsers }
      ,{ path: 'roles', component: AdminRoles }
      ,{ path: 'menus', component: AdminMenus }
    ]
  },
  
  // Original application routes
  {
    path: '/home',
    name: 'Home',
    component: MainHome,
  },
  {
    path: '/mainpage',
    name: 'MainPage',
    component: MainHome,
  },
  {
    path: '/messagehome',
    name: 'MessageHomePage',
    component: MessageHome,
  },
  {
    path: '/chat/:userId',
    name: 'PrivateChat',
    component: PrivateChat,
    props: true,
  },
  {
    path: '/search-result',
    name: 'SearchResult',
    component: SearchResult,
  },
  {
    path: '/user/:id',
    component: PersonalHome
  },
  {
    path: '/activity/:id',
    name: 'ActivityDetail',
    component: () => import('@/activity/ActivityDetail.vue'),
    props: true
  },
  // 添加通配符路由，处理所有未匹配的路由
  {
    path: '/:pathMatch(.*)*',
    redirect: '/home'
  }
];



const router = createRouter({
  // 使用hash模式代替history模式，解决刷新404问题
  history: createWebHashHistory(),
  routes,
});

export default router;
